import os
from tqdm import tqdm
from time import sleep


def getDirSizeUtil(urls, dir_size=0):
    f_list = os.listdir(urls)
    for f in f_list:
        dirs = os.path.join(urls, f)
        if os.path.isdir(dirs):
            dir_size = getDirSizeUtil(dirs, dir_size)
        else:
            dir_size += os.path.getsize(dirs)

    return dir_size


def getDirSize(urls: str):
    """
    获取文件夹的大小
    :param urls: str
    :return: float
    """
    if not os.path.exists(urls):
        print("文件夹不存在！！")
        return 0
    dir_size = getDirSizeUtil(urls)
    print("读取中......")
    for a in tqdm(range(100)):
        sleep(0.01)
    sleep(0.01)
    print("该文件夹的大小为:%.2fmb" % (dir_size / 1024 / 1024))
    return dir_size / 1024 / 1024


i = getDirSize("D:\\课堂素材")
print("获取到的返回值%.2f" % i, 'Mb')
